// worker.js
const { parentPort } = require("worker_threads");
const database = require("../sqlite/index.js");
const path = require("path");

const dbInstance = database.getDbInstance({
  dbPath: path.join(__dirname, "sqlite", "userUploadDownload.db"),
  isNotFoundCreate: true,
});
database.initialize(dbInstance);
// 从主线程接收消息
parentPort.on("message", async (message) => {
  console.log("message", message);
  const taskItem = await database.download.getDownloadByTaskid(message.taskId);
  console.log("taskItem", taskItem);
  message.port.postMessage({
    taskId: message.taskId,
    type: message.type,
    uuid: message.uuid,
    taskItem,
    msg: "进行中",
  });
});
